<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="bdId">
        <el-select v-model="queryParams.bdId" placeholder="请选择标段名称" clearable style="width: 220px"
          @change="handleQuery">
          <el-option v-for="item in bdSelect" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="zdName">
        <el-input v-model="queryParams.zdName" placeholder="请输入站点名称" clearable style="width: 220px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="" prop="fbfxName">
        <el-input v-model="queryParams.fbfxName" placeholder="请输入部位名称" clearable style="width: 220px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="" prop="approveStatus">
        <el-select v-model="queryParams.approveStatus" placeholder="请选择审批状态" style="width: 100%;" clearable
          @change="handleQuery">
          <el-option v-for="dict in dict.type.approval_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-checkbox v-model="queryParams.allProject"
          v-hasPermi="['scene:inspectionIssue:allProject']">全部项目</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>
    <el-table border stripe v-loading="loading" :data="dataList">
      <el-table-column type="index" label="序号" header-align="center" align="center" width="55" show-overflow-tooltip />
      <el-table-column label="项目名称" header-align="center" align="left" prop="projectName" min-width="150"
        show-overflow-tooltip />
      <el-table-column label="标段名称" header-align="center" align="left" prop="bdName" min-width="100"
        show-overflow-tooltip />
      <el-table-column label="站点名称" header-align="center" align="left" prop="zdName" min-width="150"
        show-overflow-tooltip />
      <el-table-column label="报验部位" align="center" prop="fbfxName" min-width="100" show-overflow-tooltip />
      <el-table-column label="报验工序" align="center" prop="name" min-width="100" show-overflow-tooltip />
      <el-table-column label="当前节点" align="center" prop="currNodeName" min-width="100" show-overflow-tooltip />
      <el-table-column label="审批状态" align="center" prop="approveStatus" min-width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.approval_status" :value="scope.row.approveStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="onView(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { listQueryBsProcessInspection } from "@/api/pl/bsProcessInspection";
import { queryBdSelect } from "@/api/base/bsBd";
import { mapGetters } from "vuex";
import Bus from "@/utils/bus";

export default {
  components: {},
  name: "QueryProcess",
  dicts: ['approval_status'],
  data () {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      bdSelect: [],
      // 现场巡查问题表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: undefined,
        bdId: undefined,
        lczh: undefined,
        wtbt: undefined,
        czwt: undefined,
        xcsj: undefined,
        zgyq: undefined,
        zgsx: undefined,
        fileId: undefined,
        approveStatus: undefined,
        allProject: undefined,
        fbfxName: undefined,
        zdName: undefined,
      },
    };
  },
  // 监听顶部全局下拉
  computed: {
    ...mapGetters(["sysProjectId", "sysProjectList", "userId"])
  },
  watch: {
    sysProjectId (newVal, oldVal) {
      this.queryParams.projectId = this.sysProjectId;
      // 系统顶部选中项目变化
      this.init();
    }
  },
  created () {
    this.queryParams.projectId = this.sysProjectId;
    this.init();
  },
  mounted () {
    // 检测依据
    Bus.$on("refresh", () => {
      this.handleQuery();
    });
  },
  beforeDestroy () {
    Bus.$off("refresh");
  },
  methods: {
    init () {
      this.getBdList();
      this.getList();
    },
    // 获取标段下拉
    getBdList () {
      queryBdSelect({ projectId: this.sysProjectId }).then(response => {
        this.bdSelect = response.data;
      });
    },

    /** 查询现场巡查问题列表 */
    getList () {
      this.loading = true;
      listQueryBsProcessInspection(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 详情
    onView (row) {
      if (!row.approveStatus || row.approveStatus == '00' || row.approveStatus == '33') {
        this.$router.push({
          path: '/processInspection/query/detail',
          query: {
            buzId: row.id,
            procInsId: row.procInsId,
            taskId: row.wfTaskVos && row.wfTaskVos[0] && row.wfTaskVos[0].taskId,
            approveStatus: row.approveStatus,
            processed: true
          }
        });
        return;
      }
      const processed = row.approveStatus == '11' && row.currApproval;
      this.$router.push({
        path: '/workflow/process/detail/' + row.procInsId,
        query: {
          taskId: row.wfTaskVos && row.wfTaskVos[0] && row.wfTaskVos[0].taskId,
          processed: processed
        }
      });
    },
  }
};
</script>
